package main;

import java.util.Scanner;

public class Console {
	private static Scanner scanner;

	static {
		scanner = new Scanner(System.in);
	}

	private Console() {
	};

	public static void print(String str) {
		System.out.print(str);
	}

	public static void println(String str) {
		System.out.println(str);
	}

	public static void println(Object obj) {
		System.out.println(obj);
	}

	public static String askInput(String str) {
		String input = null;
		while (true) {
			print(str + ">");
			input = scanner.nextLine();
			if (!"".equals(input.trim())) {
				break;
			}
			println("您的输入不合法!请输入一个非空命令！");
		}
		return input;
	}

	public static int askInputInt(String number) {
		int result = -1;
		String input = null;
		while (true) {
			try {
				input = askInput(number);
			} catch (Exception e) {
				println("请输入合法的数字");
			}
			if (result != -1) {
				break;
			}
		}
		return result;
	}

	public static int askInputInt(String str, boolean isRequired) {
		if (isRequired) {
			return askInputInt(str);
		}
		try {
			print(str + ":");
			String input = scanner.nextLine();
			return Integer.parseInt(input);
		} catch (Exception e) {
			println("不合法的数字！默认使用0.");
		}
		return 0;
	}

	public static void terminate() {
		println("再见!");
		System.exit(0);
	}
}
